#include <iostream>

using namespace std;

typedef long long LL;

const int N = 1e5 + 10;

LL a[N];
int n;

int main()
{
	cin >> n;
	LL ret = 0;
	for(int i = 1; i <= n; i++)
	{
		cin >> a[i]; 
		if(a[i] > a[i - 1]) ret += a[i] - a[i - 1];
	}
	cout << ret << endl;
	return 0;
}

